// 新注册用户
const conn = require("./conn.js")
// md5 加密
const md5 = require('md5')
var path = require('path')
module.exports = (req, res) => {
    var username = req.body.username
    var password = md5(req.body.password)
    var email = req.body.email
    var phone = req.body.phone
    var sex = req.body.sex
    var sql = 'insert into `usernode` set ? '
    // 串第二个参数，替代sql语句中的问号
    conn.query(sql, {username, password, phone, email, sex}, function (error, result) {
        if (error == null) {
            res.cookie('message', JSON.stringify({
                status: 'success',
                link: '/login',
                linkText: '登陆',
                msg: '注册成功'
            }))
            res.sendFile(path.resolve('./') + '/public/message.html')
        } else {
            console.log(result)
            res.cookie('message', JSON.stringify({
                status: 'error',
                link: '/regist',
                linkText: '重新注册',
                msg: '注册失败'
            }))
            res.sendFile(path.resolve('./') + '/public/message.html')
        }
    })
}


